#include"RpcApplication.h"

#include<iostream>
#include<unistd.h>

RpcConfig RpcApplication::m_rpcConfig;
RpcApplication::RpcApplication()
{

}
RpcApplication&  RpcApplication::getInstance()
{
     static RpcApplication rpcApplication ;
     return  rpcApplication ;
}
RpcConfig&  RpcApplication::getInstanceConfig()
{
    return m_rpcConfig;
}
void RpcApplication:: Init(int argc,char ** argv )
{
    if(argc<2)
    {
        std::cout<<"format:command -i <fonfigfile>"<<std::endl;
        exit(-1);
    }
    int c=0;
    std::string fileName;
    while((c = getopt(argc,argv,"i:"))!= -1)
    {
        switch (c)
        {
        case 'i':
             fileName=optarg;
            break;
        case '?':
              std::cout<<"invaild args"<<std::endl;
              std::cout<<"format:command -i <fonfigfile>"<<std::endl;
              break;
        default:
            break;
        }
    }
    m_rpcConfig.LoadConfigFile(fileName.c_str());
    std::cout<<"rpcserviceip"<<m_rpcConfig.Load("rpcserverip")<<std::endl;
    std::cout<<"rpcserviceport"<<m_rpcConfig.Load("rpcserverport")<<std::endl;
    std::cout<<"zookeeperip"<<m_rpcConfig.Load("zookeeperip")<<std::endl;
    std::cout<<"zookeeperport"<<m_rpcConfig.Load("zookeeperport")<<std::endl;
}
